package com.lc202407;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack {
    Queue<Integer> inQueue;
    Queue<Integer> outQueue;

    public MyStack() {
        inQueue = new LinkedList<>();
        outQueue = new LinkedList<>();
    }

    public void push(int x) {
        inQueue.add(x);
        while (!outQueue.isEmpty()) {
            inQueue.add(outQueue.poll());
        }
        Queue<Integer> tmpQueue;
        tmpQueue = inQueue;
        inQueue = outQueue;
        outQueue = tmpQueue;
    }

    public int pop() {
        return outQueue.poll();
    }

    public int top() {
        return outQueue.peek();
    }

    public boolean empty() {
        return outQueue.isEmpty();
    }
}
